package com.project.controller;

import com.project.bean.PrimaryPostBean;
import com.project.bean.UserBean;
import com.project.service.IPrimaryPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("primaryPost")
public class PrimaryPostController {
    @Autowired
    private IPrimaryPostService service;

    @RequestMapping("findAll")
    public List<PrimaryPostBean> findAll(){
        return service.findAll();
    }

    @RequestMapping("add")
    public String add(PrimaryPostBean primary, HttpServletRequest request){
        //从session中得到登陆用户
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        primary.setUser(user);

        service.add(primary);
        return "ok";
    }

    @RequestMapping("findById")
    public PrimaryPostBean findById(int id){
        return service.findById(id);
    }
}
